package chixing.day20.work3;

import java.util.List;
import java.util.Map;

public class Test3 {
    public static void main(String[] args) {
        ContractService service = new ContractService();

        // 初始化多个合同
        Contract contract1 = new Contract(1, "供应商A", "技术部", 200000, ContractStatus.DRAFT);
        Contract contract2 = new Contract(2, "供应商B", "技术部", 300000, ContractStatus.PENDING_APPROVAL);
        Contract contract3 = new Contract(3, "供应商A", "市场部", 150000, ContractStatus.DRAFT);

        service.addContract(contract1);
        service.addContract(contract2);
        service.addContract(contract3);

        // 模拟提交、审批、拒绝流程
        service.submitForApproval(1);  // 合同1提交审批
        service.approve(2);            // 合同2审批通过
        service.reject(3);             // 合同3被拒绝

        // 输出技术部合同总金额
        double techTotal = service.totalAmountByDepartment("技术部");
        System.out.println("技术部合同总金额: " + techTotal);

        // 按供应商分组合同
        Map<String, List<Contract>> grouped = service.groupBySupplier();
        System.out.print("按供应商分组合同: ");
        for (Map.Entry<String, List<Contract>> entry : grouped.entrySet()) {
            System.out.print(entry.getKey() + " -> [");
            for (int i = 0; i < entry.getValue().size(); i++) {
                if (i > 0) System.out.print(",");
                System.out.print("O" + String.format("%03d", entry.getValue().get(i).getContractId()));
            }
            System.out.print("] ");
        }
        System.out.println();
    }
}
